<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/5
 * Time: 13:56
 */
include "dataConfig.php";

// 只可以post请求
if($_SERVER["REQUEST_METHOD"] != "POST"){
    print_r(json_encode(array("status" => -1, "msg" => "不支持get")));
    return;
}

// 获取当前时间的毫秒时间戳
function msectime() {
    list($msec, $sec) = explode(' ', microtime());
    return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
}

// 获取图片，并设置图片路径
$ARR = explode('.',$_FILES["uimg"]["name"]);
$PATH = './upload-file/'.msectime().'.'.$ARR[count($ARR)-1];
// print_r(json_encode(array("status" => 1, "msg" => $PATH)));
if(move_uploaded_file($_FILES["uimg"]["tmp_name"], $PATH)){
    if(isset($_REQUEST["uname"]) && isset($_REQUEST["upwd"]) && isset($_REQUEST["urelname"])){

        $uname = $_REQUEST["uname"];
        $upwd = $_REQUEST["upwd"];
        $urelname = $_REQUEST["urelname"];
        $ugender = $_REQUEST["ugender"];
        $utel = $_REQUEST["utel"];
        $uemail = $_REQUEST["uemail"];

        // 准备SQL
        $sql = "INSERT INTO userinfo (`uname`,`urelname`,`upwd`,`ugender`,`utel`,`uemail`,`uimg`)";
        $sql .= " VALUES(?,?,?,?,?,?,?) ; ";

        // 预处理SQL
        $stmt = $conn->prepare($sql);
        $stmt->bind_param("sssssss", $uname, $urelname, $upwd, $ugender, $utel, $uemail,$PATH);

        // 获取结果
        $stmt->execute();

        // 处理结果
        if($stmt->affected_rows >= 1){
            print_r(json_encode(array("status" => 1, "msg" => "注册成功")));
        } else {
            print_r(json_encode(array("status" => 0, "msg" => "注册失败")));
        }

        $stmt->close();
        $conn->close();
    }

}